package us.gaaoc.framework.webapp.backingbeans.profile;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import javax.servlet.http.HttpSession;

import us.gaaoc.framework.webapp.backingbeans.filingSearch.SearchResults;

public class Menu implements Serializable {

	/**
	 * property for holding the court's name in the header
	 */
	private String courtHeader;
	/**
	 * property menu
	 */
	private List<Links> menu;
	/**
	 * property dataModel
	 */
	transient private DataModel dataModel;
	/**
	 * property searchWord
	 */
	private String searchWord;

	/**
	 * Constructor
	 *
	 */
	public /* required public for serialization support */ Menu() {
		
	}
	
	public Menu(String courtName)
	{
		this.menu = new ArrayList<Links>();
		this.courtHeader = courtName;
	}

	/**
	 * @return Returns the dataModel.
	 */
	public DataModel getDataModel() {
		return dataModel;
	}

	/**
	 * @param dataModel The dataModel to set.
	 */
	public void setDataModel(DataModel dataModel) {
		this.dataModel = dataModel;
	}

	/**
	 * @return Returns the searchWord.
	 */
	public String getSearchWord() {
		return searchWord;
	}

	/**
	 * @param searchWord The searchWord to set.
	 */
	public void setSearchWord(String searchWord) {
		this.searchWord = searchWord;
	}

	/**
	 * @return Returns the menu.
	 */
	public List<Links> getMenu() {
		return menu;
	}

	/**
	 * @param menu
	 *            The menu to set.
	 */
	public void setMenu(List<Links> menu) {
		this.menu = menu;
	}

	/**
	 * This method is used to logout the user from application
	 * @return String
	 */
	public String logout() {
		FacesContext facesContext = FacesContext.getCurrentInstance();
		HttpSession httpSession = (HttpSession) facesContext
				.getExternalContext().getSession(false);
		httpSession.invalidate();
		return "logOut";
	}
	
	/**
	 * This method is used to search the data from the database
	 * @return String
	 */
	@SuppressWarnings("unchecked")
	public String search(){
		if (!(this.searchWord.equals(""))) {
			Map sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
			SearchResults searchResultBean = new SearchResults();
			//searchResultBean.setDataModel(this.dataModel);
			this.setSearchWord(this.getSearchWord().replace('\'', ' '));
			this.setSearchWord(this.getSearchWord().replace('\\', ' '));
			searchResultBean.setSearchWord(this.getSearchWord());
			sessionMap.put("searchResultBean",searchResultBean);
			return "search";
		}
			else return "";
	}

	public String getCourtHeader() {
		return courtHeader;
	}

	public void setCourtHeader(String courtHeader) {
		this.courtHeader = courtHeader;
	}

}
